package org.acme.server.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;

import java.util.Date;

/**
 * @author chentao
 * @version 1.0
 * @description: TODO
 * @date 2025/3/7 下午10:32
 */
@Data
@TableName(value = "sys_server")
public class SysServer extends Model<SysServer> {

    @TableId(type = IdType.ASSIGN_ID)
    private Long id;

    @TableField(value = "host")
    private String host;

    @TableField(value = "port")
    private int port;

    @TableField(value = "is_master")
    private boolean isMaster;

    @TableField(value = "is_active")
    private boolean isActive;

    @TableField(value = "create_time")
    private Date createTime;

    @TableField(value = "update_time")
    private Date updateTime;

    @TableField(value = "refresh_time")
    private Date refreshTime;

    public void recalculateFields(){
        if (this.createTime == null){
            this.createTime = new Date();
        }
        this.updateTime = new Date();
        this.refreshTime = new Date();
    }
}
